﻿package {
	import org.flixel.*;
	import behaviors.explode.*
	import behaviors.particle.*
	import behaviors.firing.*
	public class GameState extends FlxState {
		[Embed(source = "../images/player_small.png")] public static var test_img:Class;

		public var particleGroup:FlxGroup;
		public var timerGroup:FlxGroup;
		private const MAX_PARTICLES:int = 100;
		private const MAX_TIMERS:int = 250;
		private var player:Player;
		public function GameState():void {
			//FlxG.debug = true;
			player = new Player();
			add(player);
			player.x = 50;
			player.y = 50;
			var w:Weapon = new Weapon();
			var q:WeaponBehavior = new WeaponBehavior(); 
			q.fireBehavior = new SingleShotBehavior();
			q.particleBehavior = new FlyStraightBehavior(50);
			q.explodeBehavior = new DieBehavior();
			w.weakBehavior = q;
			w.strongBehavior = q;
			w.specialBehavior = q;
			player.equip(w);
		}
		override public function create(): void {
			particleGroup = new FlxGroup();
			for (var i:int=0; i < MAX_PARTICLES; i++) {
				particleGroup.add(new Particle());
			}
			timerGroup = new FlxGroup();
			for (i=0; i < MAX_TIMERS; i++) {
				timerGroup.add(new ParticleTimer());
			}
			add(particleGroup);
			add(timerGroup);
			
		}
		override public function update():void {
			
			super.update();
		}

		public function spawnParticleTimer(timerDuration:Number, callback:Function) : void {
			var t:ParticleTimer = (timerGroup.getFirstAvail() as ParticleTimer);
			t.spawn(timerDuration, callback);
		}

		public function spawnParticleAtPlayer():Particle {
			var p:Particle = (particleGroup.getFirstAvail() as Particle);
			p.spawn(player.x, player.y, test_img);	
			return p;
		}

	}
}

